package com.greysh.enter.action;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.SessionAware;
import com.greysh.enter.model.Admin;
import com.greysh.enter.service.AdminService;
import com.opensymphony.xwork2.ActionSupport;

public class AdminAction extends ActionSupport implements SessionAware {

	private static final long serialVersionUID = 1L;

	Admin admin;
	AdminService adminService;

	private Map<String, Object> session;
	private HttpServletRequest request;

	private int testId;
	private int userId;
	private int scoreId;

	Admin tempAdmin;

	// 管理员登录验证
	public String login() {
		try {
			tempAdmin = adminService.findAdminByName(admin.getAdminName());
			if ((tempAdmin.getAdminPassword()).equals(admin.getAdminPassword())) {
				session.put("admin", tempAdmin);
				System.out.println("Success");
				return "login_success";
			}
			System.out.println("Falied");
			return "login_success";
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("Falied");
			return "login_success";
		}
	}

	public Admin getAdmin() {
		return admin;
	}

	public void setAdmin(Admin admin) {
		this.admin = admin;
	}

	public AdminService getAdminService() {
		return adminService;
	}

	public void setAdminService(AdminService adminService) {
		this.adminService = adminService;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public int getTestId() {
		return testId;
	}

	public void setTestId(int testId) {
		this.testId = testId;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public int getScoreId() {
		return scoreId;
	}

	public void setScoreId(int scoreId) {
		this.scoreId = scoreId;
	}

	public Admin getTempAdmin() {
		return tempAdmin;
	}

	public void setTempAdmin(Admin tempAdmin) {
		this.tempAdmin = tempAdmin;
	}

}
